<?php

namespace app\admin\controller;


use app\admin\model\Coil;
use cmf\controller\AdminBaseController;
use OpenApi\Annotations\Examples;
use think\facade\Db;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

/**
 * Class CoilController
 * @package app\admin\controller
 * @adminMenuRoot(
 *     'name'   =>'钢卷库存',
 *     'action' =>'index',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 10000,
 *     'icon'   =>'',
 *     'remark' =>''
 * )
 */
class CoilController extends AdminBaseController
{
    /**excel 导出
     *      *   @adminMenu(
     *     'name'   => 'excel导出',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '接收计划',
     *     'param'  => ''
     * )
     * @return void
     */
    public function outexcel()
    {
        //要导出的数据,二维
        $lists = Coil::order('id desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', 0);
        $lists = $lists->paginate(['list_rows' => 10000000, 'query' => [
            //'key_status' => $key_status
        ]]);

        $data = $lists->toArray();
        $data = $data['data'];
        $newdata = array();

//类型
        $type = array(1 => '成品库', 2 => '实验库', 3 => '废料库', 4 => '半成品库', 5 => '头尾库', 6 => '封闭库', 7 => '原料库', 8 => '委外库');

        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');

        $company_id_arr = Db::name('company')
            ->column('name', 'id');

        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');

        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');

        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');

        $plate_id_arr = Db::name('plate')
            ->column('name', 'id');
        $coil_id_arr_da = Db::name('coil')
            ->column('coilno', 'id');

        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');
        foreach ($data as $k => $vo) {
            $newdata[$k] = $vo;
            $newdata[$k]['add_time'] = date('Y-m-d H:i', $vo['add_time']);
            $newdata[$k]['update_time'] = date('Y-m-d H:i', $vo['update_time']);
            $newdata[$k]['loadingtime'] = date('Y-m-d H:i', $vo['loadingtime']);
//            $newdata[$k]['type'] = $type[$vo['type']];
//            $newdata[$k]['grade_id'] = isset($grade_id_arr[$vo['grade_id']]) ? $grade_id_arr[$vo['grade_id']] : '';
            $newdata[$k]['steel_grade_id'] = isset($steel_grade_id_arr[$vo['steel_grade_id']]) ? $steel_grade_id_arr[$vo['steel_grade_id']] : '';
//            $newdata[$k]['coil_id'] = isset($coil_id_arr_da[$vo['coil_id']]) ? $coil_id_arr_da[$vo['coil_id']] : '';
//            $newdata[$k]['ht_id'] = isset($ht_id_arr[$vo['ht_id']]) ? $ht_id_arr[$vo['ht_id']] : '';
            $newdata[$k]['company_id'] = isset($company_id_arr[$vo['company_id']]) ? $company_id_arr[$vo['company_id']] : '';
//            $newdata[$k]['parent_id'] = isset($plate_id_arr[$vo['parent_id']]) ? $plate_id_arr[$vo['parent_id']] : '';
            $newdata[$k]['admin_id'] = isset($user_arr[$vo['admin_id']]) ? $user_arr[$vo['admin_id']] : '';
            $newdata[$k]['companytype'] = isset($companytypea_arr[$vo['companytype']]) ? $companytypea_arr[$vo['companytype']] : '';
            $newdata[$k]['property_id'] = isset($company_id_arr[$vo['property_id']]) ? $company_id_arr[$vo['property_id']] : '';
            $newdata[$k]['company_id'] = isset($company_id_arr[$vo['company_id']]) ? $company_id_arr[$vo['company_id']] : '';
            $newdata[$k]['steel_mill'] = isset($company_id_arr[$vo['steel_mill']]) ? $company_id_arr[$vo['steel_mill']] : '';

        }

        $head = array(
            '捆包号',
            '采购订单号',
            '钢卷号',
            '原料钢种',
            '厚',
            '宽',
            '长',
            '重',
            '库位',
            '被占重量',
            '入库时间',
            '成品品名',
            '归属类型',
            '产权类型',
            '客户名称',
            '所属钢厂',
            '添加时间',
            '更新时间',
            '最后操作人');

        //数据中对应的字段，用于读取相应数据：
//        $keys = [
//            'name',
//            'coilno',
//            'product',
//            'companytype',
//            'steel_grade_id',
//            'd',
//            'w',
//            'h',
//            'weight',
//            'occupied_we',
//            'loadingtime',
//            'company_id',
//            'locator',
//            'add_time',
//            'update_time',
//            'admin_id',
//        ];
        $keys = [
            'name',
            'po_name',
            'coilno',
            'steel_grade_id',
            'd',
            'w',
            'h',
            'weight',
            'locator',
            'occupied_we',
            'loadingtime',
            'product',
            'companytype',
            'property_id',
            'company_id',
            'steel_mill',
            'add_time',
            'update_time',
            'admin_id'
        ];

//        $head = array('id', 'name');//设置表头
//        $keys = ['id','name'];//数据中表头对应的字段，用于读取相应数据
//        var_dump($data);
        excel_out('钢卷导出' . date('ymdhis', time()), $newdata, $head, $keys);

    }
    /**excel 已出库导出
     *      *   @adminMenu(
     *     'name'   => 'excel已出库导出',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => 'excel已出库导出',
     *     'param'  => ''
     * )
     * @return void
     */
    public function outexceldel()
    {
        //要导出的数据,二维
        $lists = Coil::order('id desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', '>',0);
        $lists = $lists->paginate(['list_rows' => 10000000000, 'query' => [
            //'key_status' => $key_status
        ]]);

        $data = $lists->toArray();
        $data = $data['data'];
        $newdata = array();

//类型
        $type = array(1 => '成品库', 2 => '实验库', 3 => '废料库', 4 => '半成品库', 5 => '头尾库', 6 => '封闭库', 7 => '原料库', 8 => '委外库');

        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');

        $company_id_arr = Db::name('company')
            ->column('name', 'id');

        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');

        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');

        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');

        $plate_id_arr = Db::name('plate')
            ->column('name', 'id');
        $coil_id_arr_da = Db::name('coil')
            ->column('coilno', 'id');

        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');
        foreach ($data as $k => $vo) {
            $newdata[$k] = $vo;
            $newdata[$k]['add_time'] = date('Y-m-d H:i', $vo['add_time']);
            $newdata[$k]['update_time'] = date('Y-m-d H:i', $vo['update_time']);
            $newdata[$k]['loadingtime'] = date('Y-m-d H:i', $vo['loadingtime']);
//            $newdata[$k]['type'] = $type[$vo['type']];
//            $newdata[$k]['grade_id'] = isset($grade_id_arr[$vo['grade_id']]) ? $grade_id_arr[$vo['grade_id']] : '';
            $newdata[$k]['steel_grade_id'] = isset($steel_grade_id_arr[$vo['steel_grade_id']]) ? $steel_grade_id_arr[$vo['steel_grade_id']] : '';
//            $newdata[$k]['coil_id'] = isset($coil_id_arr_da[$vo['coil_id']]) ? $coil_id_arr_da[$vo['coil_id']] : '';
//            $newdata[$k]['ht_id'] = isset($ht_id_arr[$vo['ht_id']]) ? $ht_id_arr[$vo['ht_id']] : '';
            $newdata[$k]['company_id'] = isset($company_id_arr[$vo['company_id']]) ? $company_id_arr[$vo['company_id']] : '';
//            $newdata[$k]['parent_id'] = isset($plate_id_arr[$vo['parent_id']]) ? $plate_id_arr[$vo['parent_id']] : '';
            $newdata[$k]['admin_id'] = isset($user_arr[$vo['admin_id']]) ? $user_arr[$vo['admin_id']] : '';
            $newdata[$k]['companytype'] = isset($companytypea_arr[$vo['companytype']]) ? $companytypea_arr[$vo['companytype']] : '';
            $newdata[$k]['property_id'] = isset($company_id_arr[$vo['property_id']]) ? $company_id_arr[$vo['property_id']] : '';
            $newdata[$k]['company_id'] = isset($company_id_arr[$vo['company_id']]) ? $company_id_arr[$vo['company_id']] : '';
            $newdata[$k]['steel_mill'] = isset($company_id_arr[$vo['steel_mill']]) ? $company_id_arr[$vo['steel_mill']] : '';

        }

        $head = array(
            '捆包号',
            '采购订单号',
            '钢卷号',
            '原料钢种',
            '厚',
            '宽',
            '长',
            '重',
            '库位',
            '被占重量',
            '入库时间',
            '成品品名',
            '归属类型',
            '产权类型',
            '客户名称',
            '所属钢厂',
            '添加时间',
            '更新时间',
            '最后操作人');

        //数据中对应的字段，用于读取相应数据：
//        $keys = [
//            'name',
//            'coilno',
//            'product',
//            'companytype',
//            'steel_grade_id',
//            'd',
//            'w',
//            'h',
//            'weight',
//            'occupied_we',
//            'loadingtime',
//            'company_id',
//            'locator',
//            'add_time',
//            'update_time',
//            'admin_id',
//        ];
        $keys = [
            'name',
            'po_name',
            'coilno',
            'steel_grade_id',
            'd',
            'w',
            'h',
            'weight',
            'locator',
            'occupied_we',
            'loadingtime',
            'product',
            'companytype',
            'property_id',
            'company_id',
            'steel_mill',
            'add_time',
            'update_time',
            'admin_id'
        ];


//        $head = array('id', 'name');//设置表头
//        $keys = ['id','name'];//数据中表头对应的字段，用于读取相应数据
//        var_dump($data);
        excel_out('钢卷已出库导出' . date('ymdhis', time()), $newdata, $head, $keys);

    }

    public function index()
    {
        //搜索部分
//        $key_status = input('get.key_status/d');

        $lists = Coil::order('id desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', 0);
        $lists = $lists->paginate(['list_rows' => 100, 'query' => [
            //'key_status' => $key_status
        ]]);
        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');

        $this->assign('user_arr', $user_arr);

        $grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');
//        var_dump($grade_id_arr);
        $this->assign('grade_id_arr', $grade_id_arr);
        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');
        $this->assign('companytypea_arr', $companytypea_arr);

        $company_id_arr = Db::name('company')
            ->column('name,abb_name', 'id');
        $this->assign('company_id_arr', $company_id_arr);
//        var_dump($lists);
//        foreach ($lists as $k=>$v){
//            var_dump($v['company_id']);
//        }

        return $this->fetch('', ['lists' => $lists->toArray(), 'page' => $lists->render(), 'domain' => request()->domain() . '/upload/']);
    }
    /**
     * @adminMenu(
     *     'name'   => '钢卷已出库',
     *     'parent' => 'indexdel',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '钢卷已出库',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function indexdel()
    {
        //搜索部分
//        $key_status = input('get.key_status/d');

        $lists = Coil::order('name,delete_time desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', '>',0);
        $lists = $lists->paginate(['list_rows' => 100, 'query' => [
            //'key_status' => $key_status
        ]]);
        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');

        $this->assign('user_arr', $user_arr);

        $grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');
//        var_dump($grade_id_arr);
        $this->assign('grade_id_arr', $grade_id_arr);
        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');
        $this->assign('companytypea_arr', $companytypea_arr);

        $company_id_arr = Db::name('company')
            ->column('name,abb_name', 'id');
//        var_dump($company_id_arr);
        $this->assign('company_id_arr', $company_id_arr);

        return $this->fetch('', ['lists' => $lists->toArray(), 'page' => $lists->render(), 'domain' => request()->domain() . '/upload/']);
    }

    /**
     * @adminMenu(
     *     'name'   => '新增',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '新增',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function add()
    {
//        $today = date('ymd', time());
//        $name='';
////        $this->success('ok', '',$today);
//        $newnum = Db::name('plate_num')->where('today', $today)->order('id desc')->find();
//        if ($newnum) {
//            Db::name('plate_num')->insertGetId(array('today' => $today, 'order_num' => $newnum['order_num'] + 1, 'addtime' => time(),
//                'admin_id' => cmf_get_current_admin_id()));
//            $dd = str_pad($newnum['order_num'] + 1, 5, '0', STR_PAD_LEFT);
//            $name = 'Y' . $today . $dd;
//
//        } else {
//            Db::name('plate_num')->insertGetId(array('today' => $today, 'order_num' => 1, 'addtime' => time(),
//                'admin_id' => cmf_get_current_admin_id()));
//            $dd = str_pad(1, 5, '0', STR_PAD_LEFT);
//
//            $name = 'Y' . $today . $dd;
//        }
//        $this->assign('name',$name);
        $companytypea_arr = array(0 => array('id' => 1, 'name' => '自主'), 1 => array('id' => 2, 'name' => '来料'), 2 => array('id' => 3, 'name' => '委外'));
        $this->assign('companytypea_arr', $companytypea_arr);

        $grade_id_arr = Db::query('select id,name from cmf_steel_grade where delete_time =0');
        $this->assign('grade_id_arr', $grade_id_arr);
        $company_id_arr = Db::query('select id,name,abb_name from cmf_company where delete_time =0');
        $this->assign('company_id_arr', $company_id_arr);
        return $this->fetch('', ['domain' => request()->domain() . '/upload/']);
    }

    /**
     * @adminMenu(
     *     'name'   => '新增提交',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '新增提交',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function addPost()
    {

        $params = array_map(function ($v) {
            return is_array($v) ? implode(',', $v) : $v;
        }, input('post.'));

        if (!$params) {
            $this->error('非法参数');
        }

        $params['loadingtime'] = strtotime($params['loadingtime']);
        $params['update_time'] = time();
        $params['add_time'] = time();
        $params['admin_id'] = cmf_get_current_admin_id();

        $id = Db::name('coil')->insertGetId($params);

        $params['id'] = $id;
        cmf_install_log($params, 'coil_log', 'add');

        $this->success('操作成功', 'index');
    }
    public function updateprice()
    {
        $po_price = input('po_price');
        $id = input('id');
//
        $params['po_price'] = $po_price;
        $params['id'] = $id;
        $params['update_time'] = time();
        $params['admin_id'] = cmf_get_current_admin_id();
        Coil::update($params);
        cmf_install_log($params, 'coil_log', 'update');
        $this->success('成功');
    }
    /**
     * @adminMenu(
     *     'name'   => '修改',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '修改',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function edit()
    {
        $id = input('get.id/d');

        if (!is_numeric($id)) {
            $this->error('非法参数');
        }
        $companytypea_arr = array(0 => array('id' => 1, 'name' => '自主'), 1 => array('id' => 2, 'name' => '来料'), 2 => array('id' => 3, 'name' => '委外'));
        $this->assign('companytypea_arr', $companytypea_arr);

        $res = Coil::where('id', $id)->find();
        $grade_id_arr = Db::query('select id,name from cmf_steel_grade where delete_time =0');
        $this->assign('grade_id_arr', $grade_id_arr);
        $company_id_arr = Db::query('select id,name,abb_name from cmf_company where delete_time =0');
        $this->assign('company_id_arr', $company_id_arr);

        return $this->fetch('', ['vo' => $res, 'domain' => request()->domain() . '/upload/']);
    }

    /**
     * @adminMenu(
     *     'name'   => '修改提交',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '修改提交',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function editPost()
    {
        $params = array_map(function ($v) {
            return is_array($v) ? implode(',', $v) : $v;
        }, input('post.'));
//        var_dump($params['company_id']);
//        exit();
        if (!$params || empty($params['id'])) {
            $this->error('非法参数');
        }
        $params['loadingtime'] = strtotime($params['loadingtime']);
        $params['update_time'] = time();
        $params['admin_id'] = cmf_get_current_admin_id();

        Coil::update($params);
        cmf_install_log($params, 'coil_log', 'update');
        $this->success('操作成功', 'index');
    }

    /**
     * @adminMenu(
     *     'name'   => '删除',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function del()
    {
        $id = input('get.id/d');

        if (!(is_numeric($id) && $id > 0)) {
            $this->error('非法参数');
        }

        Coil::where('id', $id)->update(array('delete_time' => time(),'update_time'=>time(), 'admin_id' => cmf_get_current_admin_id()));
        $params = Db::name('coil')->where('id', $id)->find();
        cmf_install_log($params, 'coil_log', 'del');
        $this->success('删除成功');
    }

    public function field()
    {
        $id = input('get.id/d');
        $field = input('get.field');

        if (!(is_numeric($id) && $id > 0 && $field)) {
            $this->error('非法参数');
        }

        $info = Coil::field($field)->where('id', $id)->find();

        $this->success('ok', '', $info[$field]);
    }

    public function selctid()
    {
        $id = input('get.id/d');
        $infod = Coil::where('steel_grade_id', $id)->where('delete_time', 0)->select();
        $this->success('ok', '', $infod);
    }

    public function import()
    {
//http://172.20.2.2/upload/admin/20221021/e23a2bc833856b2faac4a22b256befc3.xlsx
        //$file为本地文件地址
        $file = "upload/admin/20221021/e23a2bc833856b2faac4a22b256befc3.xlsx";
        $data = inpor($file);

//        $excel_model = array('导入识别码', '业主类型', '业主名称', '性别', '电子邮箱', '证件类型', '证件号码', '主要联系手机', '备用联系电话', '出生日期', '职业', '籍贯', 'QQ', '微信号', '兴趣爱好', '现住地址', '业主备注');
//        $excel_title = $data[1];//excel头部标题部分
//        if ($excel_title !== $excel_model) {
//            $this->ajaxReturn(['status' => -1, 'msg' => 'excel数据格式错误,请下载并参照excel模板']);
////            $this->error('excel数据格式错误,请下载并参照excel模板', U('Property/house/owner_import'));
//        }

        var_dump($data);//得到了Excel中的数据，可进行插入数据库等操作
    }

    /**
     * @adminMenu(
     *     'name'   => '确认入库',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function confirm()
    {
        $id = input('get.id/d');

        if (!(is_numeric($id) && $id > 0)) {
            $this->error('非法参数');
        }
        $name = getname(7);
//        var_dump($name);
        Coil::where('id', $id)->update(array('name' => $name));
        $params = Db::name('coil')->where('id', $id)->find();
        cmf_install_log($params, 'coil_log', 'update');
        $this->success('操作成功', 'index');
//        $this->success('成功');
    }


    /**
     *列表
     * @adminMenu(
     *     'name'   => '钢卷打印',
     *     'parent' => 'index',
     *     'display'=> true,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '',
     *     'param'  => ''
     * )
     */
    public function tcpdf()
    {
        $id=input('id');
        if (empty($id)){
            $this->error('数据不全');
        }
        $info= Coil::where('id', $id)->find();
        if (!$info){
            $this->error('数据不全');
        }
        $info['weight']=$info['weight']*1000;
//        getPageSizeFromFormat();
        $pdf = new \TCPDF('C', 'mm', array(120,175));

        //新建一个PDF文档
        //L 横排   P竖排
        $orientation = 'P';
        $unit = 'mm';
        $format = 'A4';
        $unicode = true;
        $encoding = 'UTF-8';
        $diskcache = false;
        $pdfa = false;
//        $pdf = new \TCPDF('C', 'mm', 'A4', true, 'UTF-8',false, array(120,110));

        // set document information
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('钢卷打印');
        $pdf->SetTitle('钢卷打印');
        $pdf->SetSubject('TCPDF Tutorial');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');

        // set default header data
        //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 048', PDF_HEADER_STRING);

        // set header and footer fonts
        //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        //$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $pdf->setCellPaddings(0, 0, 0, 0);
        // set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

        // set margins
        $pdf->SetMargins(2, 35, 2);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        $pdf->SetFillColor( 232, 239, 242 );
        $pdf->Rect( 0, 0, $pdf->getPageWidth(), $pdf->getPageHeight(), 'F' );
        // set auto page breaks
//        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

        // set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

        $pdf->SetFont('stsongstdlight','B', 10);
//        $pdf->SetFont('droidsansfallback', '', 10);
//        $pdf->SetFont(‘droidsansfallback’, ”, 12);

        // add a page
        $pdf->AddPage();
        $pdf->Write(0, '', '', 0, 'L', true, 0, false, false, 0);

//        $pdf->setCellHeightRatio(1.3);
//        $pdf->SetLineWidth(2);

        $info['add_time']=date('Y-m-d',$info["add_time"]);

//类型
        $type = array(1 => '成品库', 2 => '实验库', 3 => '废料库', 4 => '半成品库', 5 => '头尾库', 6 => '封闭库', 7 => '原料库', 8 => '委外库');

        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');

        $company_id_arr = Db::name('company')
            ->column('name', 'id');

        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');

        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');

        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');
//
//        $plate_id_arr = Db::name('plate')
//            ->column('name', 'id');
//        $coil_id_arr_da = Db::name('coil')
//            ->column('coilno', 'id');

        $info['type'] = isset($type[$info['type']]) ? $type[$info['type']] : '';
        $info['grade_id'] = isset($grade_id_arr[$info['grade_id']]) ? $grade_id_arr[$info['grade_id']] : '';
        $info['steel_grade_id'] = isset($steel_grade_id_arr[$info['steel_grade_id']]) ? $steel_grade_id_arr[$info['steel_grade_id']] : '';
//        $info['coil_id'] = isset($coil_id_arr_da[$info['coil_id']]) ? $coil_id_arr_da[$info['coil_id']] : '';
        $info['ht_id'] = isset($ht_id_arr[$info['ht_id']]) ? $ht_id_arr[$info['ht_id']] : '';
        $info['company_id'] = isset($company_id_arr[$info['company_id']]) ? $company_id_arr[$info['company_id']] : '华星科技';
        $info['parent_id'] = isset($plate_id_arr[$info['parent_id']]) ? $plate_id_arr[$info['parent_id']] : '';
        $info['admin_id'] = isset($user_arr[$info['admin_id']]) ? $user_arr[$info['admin_id']] : '';
        $info['companytype'] = isset($companytypea_arr[$info['companytype']]) ? $companytypea_arr[$info['companytype']] : '';
        $info['d']=floatval($info['d']);
        $tbl = <<<EOD
<table border="1" cellspacing="0"   style="text-align: center; ">

    <tbody>
    <tr>
        <td width="30%" colspan="3" style="vertical-align: middle; vertical-align: middle; ">
          <img src="/upload/admin/20230717/b45673cca6a93a59f473d888571d0537.png" width="170" height="120">
       
        </td>
        <td width="70%" colspan="7" align="center">
         <div > 山东华星新材料科技有限公司</div>
          
          <div style="font-size:0.8em;">Shandong Huaxing New Material Tech Co., Ltd</div>
        </td>
    </tr>
    <tr>
        <td width="60%" align="center" colspan="7">
          <div>钢卷号    Coil No</div>
            <div >{$info['coilno']}</div>
        </td>
        <td width="40%" align="center" colspan="3">
            <div>品名  Product</div>
            <div >钢卷</div> 
        </td>
    </tr>
    <tr>
        <td width="60%" align="center" colspan="7">
            <div >捆包号 Bundle Package No</div>
            <div >{$info['name']}</div>
        </td>
        <td width="40%" align="center" colspan="3">
            <div >牌号  Grade</div>
            <div >{$info['steel_grade_id']}</div>
        </td>
    </tr>
    <tr>
        <td width="45%" align="center" colspan="7">
            <div >日期 Date</div>
            <div > {$info['add_time']}</div>
        </td>
        <td width="55%" align="center" colspan="3">
            <div >规格 Size</div>
            <div>{$info['d']}*{$info['w']}*{$info['h']}</div>
        </td>
    </tr>
    <tr>
        <td width="45%" align="center" colspan="7">
            <div >理重  T,W,(kg)</div>
            <div >{$info['weight']}</div>
        </td>
        <td width="55%" align="center" colspan="7"  >
            <div >客户名称 Customer Name</div>
            {$info['company_id']}{$info['companytype']}
        </td>
    </tr>
   
    <tr>
        <td  align="left" colspan="14">
           <img src="/upload/admin/20230717/393245c454f52b2f881122ba0f77ec1c.png" width="66" height="66">
        </td>

    </tr>
  
    </tbody>
</table>







EOD;

        $pdf->writeHTML($tbl, true, false, false, false, '');

        // -----------------------------------------------------------------------------

        //Close and output PDF document
        $pdf->Output('收据单_' . date('YmdHis') . '.pdf', 'I');
        exit();
    }
}